//
//  MK_SmallPlayer.m
//  miku直播
//
//  Created by 杨尚达 on 2017/7/29.
//  Copyright © 2017年 杨尚达. All rights reserved.
//

#import "MK_SmallPlayer.h"
#import "MK_BarrageManager.h"
#import "MK_Barrage_FloatView.h"
#define fontsize 16

@interface MK_SmallPlayer () <CAAnimationDelegate>


@end

@implementation MK_SmallPlayer


-(void)viewDidLoad{
    [super viewDidLoad];
    [self setupUI];
}

-(void)setupUI{
    MK_Barrage_FloatView* floatView = [MK_Barrage_FloatView new];
    [self.view addSubview:floatView];
    [floatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    self.view.backgroundColor = [UIColor blackColor];
    UIButton* backButton = [UIButton new];
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"back_pressed"] forState:UIControlStateHighlighted];
    [self.view addSubview:backButton];
    [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(16);
    }];
    [[backButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id  _Nullable x) {
        [_superVC dismissViewControllerAnimated:YES completion:nil];
    }];
    
    UIButton* pause = [UIButton new];
    [pause setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
    [pause setImage:[UIImage imageNamed:@"pause_pressed"] forState:UIControlStateHighlighted];
    [self.view addSubview:pause];
    [[pause rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id  _Nullable x) {
        pause.selected = !pause.selected;
        if (pause.selected) {
            [pause setImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
            [pause setImage:[UIImage imageNamed:@"play_pressed"] forState:UIControlStateHighlighted];
            [self.hlsPlayer pause];
        }else{
            [pause setImage:[UIImage imageNamed:@"pause"] forState:UIControlStateNormal];
            [pause setImage:[UIImage imageNamed:@"pause_pressed"] forState:UIControlStateHighlighted];
            [self.hlsPlayer play];
        }
    }];
    [self.view addSubview:pause];
    [pause mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.bottom.offset(-16);
    }];
    
    UIButton* fullBut = [UIButton new];
    [fullBut setImage:[UIImage imageNamed:@"fullscreen"] forState:UIControlStateNormal];
    [fullBut setImage:[UIImage imageNamed:@"fullscreen_pressed"] forState:UIControlStateHighlighted];
    [self.view addSubview:fullBut];
    [fullBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-10);
        make.right.offset(-10);
    }];
    
    [[fullBut rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id  _Nullable x) {
        if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait||[UIDevice currentDevice].orientation == UIDeviceOrientationPortraitUpsideDown) {
            [[UIDevice currentDevice] MK_doOrientation:UIInterfaceOrientationLandscapeLeft];
        }else{
            [[UIDevice currentDevice] MK_doOrientation:UIInterfaceOrientationPortrait];
        }
        
    }];
}

@end
